package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.demo.entity.Blog;
import com.example.demo.excel.BlogExcel;
import com.example.demo.mapper.BlogMapper;
import com.example.demo.service.IBlogService;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;

@Service
@AllArgsConstructor
public class IBlogServiceImpl extends BaseServiceImpl<BlogMapper, Blog> implements IBlogService {

	private BlogMapper blogMapper;

	@Override
	public IPage<Blog> selectBlogPage(IPage<Blog> page, Blog blog) {
		return page.setRecords(blogMapper.selectBlogPage(page, blog));
	}
	@Override
	public R blogSave(Blog blog) {
		return R.status(this.save(blog));

	}

	@Override
	public R blogUpdate(Blog blog) {
		return R.status(this.updateById(blog));
	}

	@Override
	public R blogRemove(String ids) {
		return R.status(this.deleteLogic(Func.toLongList(ids)));
	}

	@Override
	public void importBlog(List<BlogExcel> data) {
		data.forEach(blogExcel -> {
			Blog blog = Objects.requireNonNull(BeanUtil.copy(blogExcel, Blog.class));
			this.save(blog);
		});
	}

	@Override
	public List<BlogExcel> exportBlog(Wrapper<Blog> queryWrapper) {
		return blogMapper.exportBlog(queryWrapper);
	}
}
